﻿@using TSites.Core.Domain.UserMangerment
@using TSites.Common.Enums
@model System.Collections.IList
@{ Layout = null; int modelCount;}

@if (Model != null && (modelCount = Model.Count) > 0)
{
	@*@Html.Partial("PagingView", (TSites.Administrator.Models.PagingInfo)ViewBag.PageInfo);*@
	<table border="1">
		<tr>
		<th>UserId</th>
		<th>Username</th>
		<th>Email</th>
		<th>ActiveCode</th>
		<th>ActiveDate</th>
		<th>LasLogonDate</th>
		<th>CreateUserId</th>
		<th>CreateDate</th>
		<th>Action</th>
	</tr>
		@foreach (User item in Model)
		{
			<tr>
				<td>@item.ID</td>
				<td>@item.UserName</td>
				<td>@item.Email</td>
				<td><a id="@item.ID" class="activeCode" href="#">@((ACTIVE_CODE)item.ActiveCode)</a></td>
				<td>@item.ActiveDate</td>
				<td>@item.LastLoginDate</td>
				<td>@item.CreateUserId</td>
				<td>@item.CreateDate</td>
				<td>@Html.ActionLink("edit", "Edit", "UserManagement", new { id = item.ID }, null)
					<a id="@item.Email" class="resetPwd" href="#">Reset Pwd</a>
					<a id="@item.ID" class="delete" href="#">Delete</a>
				</td>
			</tr>
		}
	</table>
	@Html.Partial("PagingView", (TSites.Administrator.Models.PagingInfo)ViewBag.PageInfo);
}
else
{
	@: NOT FOUND DATA
}

<script type="text/javascript">
	$('document').ready(function () {
		// update active code
		$('a.activeCode').each(function (index) {
			var id = $(this).attr("id");
			if (id != null && id != "") {
				$(this).click(function () {
					var msg = "Please enter Active Code:<br/>"
					msg += "Successful Active: 0<br/>"
					msg += "Active by email: 1<br/>"
					msg += "Must change password: 2<br/>"
					msg += "Lock: 3<br/>"
					jPrompt(msg, null, function (result) {
						if (result != null && result != "") {
							alert(result);
						}
					});
				});
			}
		});
		// reset password link
		$('a.resetPwd').each(function (index) {
			var email = $(this).attr("id");
			if (email != null && email != "") {
				$(this).click(function () {
					var msg = "Are you sure you want to reset password of this User?"
					jConfirm(msg, null, function (result) {
						if (result == true) {
							jAlert("New password has just sent to Email: " + email);
						}
					});
				});
			}
		});
		// delete link
		$('a.delete').each(function (index) {
			var id = $(this).attr("id");
			if (id != null && id != "") {
				$(this).click(function () {
					var msg = "Are you sure you want to delete UserId: " + id + "?";
					jConfirm(msg, null, function (e) {
						if (e == true) {
							jAlert("Deleted");
						}
					});
				});
			}
		});
	});
</script>